const cookie = {
  setItem(key, val, ops={}){
    let p = ops.path ? ";path=" + ops.path : "";
    let e = "";
    if(ops.expires){
      const d = new Date();
      d.setDate( d.getDate() + ops.expires );
      e = ";expires="+d;
    }
    document.cookie = `${key}=${val}${p}${e}`;
  },
  removeItem(key, ops={}){
    this.setItem(key, "", {expires: -1, ...ops});
  },
  getItem(key){
    const arr = document.cookie.split("; ");
    for(let i=0;i<arr.length;i++){
      const c = arr[i].split("=");
      if(c[0] === key){
        return c[1];
      }
    }
    return null;
  }
}